﻿using System;
using System.Configuration;
using System.Web.Configuration;

namespace VioletDevelopmentLaboratory.Net.Web.Configuration
{
	public abstract class ConfigurationManagerBase
	{
		private bool forceSaveAll;
		public bool ForceSaveAll
		{
			get { return this.forceSaveAll; }
			set { this.forceSaveAll = value; }
		}

		private ConfigurationSaveMode saveMode;
		public ConfigurationSaveMode SaveMode
		{
			get { return this.saveMode; }
			set { this.saveMode = value; }
		}

		private System.Configuration.Configuration webConfig;

		protected ConfigurationManagerBase()
		{
			webConfig = WebConfigurationManager.OpenWebConfiguration("~/");
			this.SaveMode = ConfigurationSaveMode.Minimal;
		}

		protected ConfigurationSection GetConfigurationSection(string sectionName)
		{
			return this.webConfig.GetSection(sectionName);
		}

		public static object GetReadOnlyConfigurationSection(string sectionName)
		{
			return WebConfigurationManager.GetWebApplicationSection(sectionName);
		}

		public void Save()
		{
			this.webConfig.Save(this.saveMode, this.forceSaveAll);
		}
	}
}
